<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .mask{
      position: fixed;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      background-color: rgba(0,0,0,.8);
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .content{
      width: 50%;
      height: 50%;
      background-color: #fff;
    }
  </style>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp();
    const CommonHead =  {
      template: `
        <div>
          <h2>公共头部组件</h2>  
          <button @click="showModal">显示弹窗</button>
          <Teleport to="body">
            <div class="mask" @click.self="hideModal" v-show="isShow">
              <div class="content">
                这是内容  
              </div>  
            </div>
          </Teleport>
        </div>
      `,
      data(){
        return {
          isShow: false   
        }
      },
      methods: {
        showModal(){
          this.isShow = true
        },
        hideModal(){
          this.isShow = false
        }
      }
    }
    app.component('CommonHead', CommonHead)

    app.mount('#app')
  </script>
</body>
</html>